/* eslint-disable */
/**
 * @author Timmy.tan 630514215@qq.com
 * @date 2021/7/7
 */
const chalk = require('chalk'); // 显示
const path = require('path');
const root = path.resolve(process.cwd()); // 当前文件根目录
const {NodeSSH} = require('node-ssh');  // node-ssh 插件
const ssh = new NodeSSH();
const zip_file_path = path.join(root, '/dist'); //本地 打包的文件
const upload_file_path = `/home/wwwroot/${process.argv[2] == 'dev' ? 'testnft.nft-stk.com' : 'www.nft-stk.com'}/`; // 服务器 指定 前端静态 文件地址
const deploy = async () => {
    await ssh.connect({
        host: '8.210.207.106',
        username: 'root',
        password: 'Coolman123',
        port: 22,
    });
    // 以下 方法 将 dist 文件 夹 直接 扔到服务器 地址里面
    await ssh.putDirectory(zip_file_path, upload_file_path, {
        tick: (localPath, remotePath, error) => {
            if (error) {
                console.log(error)
                console.log(chalk.red(`failed=>${localPath}`))
            } else {
                console.log(chalk.green(`success: "${localPath}" => "${remotePath}"`))
            }
        }
    }).then(function (status) {
        console.log('the directory transfer was', status ? 'successful' : 'unsuccessful')
    })
    process.exit(0);
};
deploy().catch((e) => {
    console.log(e);
    process.exit(0);
});
